package com.ostrich.cloud.ostrichOrderService.component;

import cn.hutool.core.bean.BeanUtil;
import com.ostrich.cloud.ostrichOrderService.app.OrderManagerApiImp;
import com.ostrich.cloud.ostrichOrderService.infra.model.Order1;
import com.ostrich.cloud.ostrichOrderService.model.dto.StoreOrderDto;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;

@Component
@RocketMQMessageListener(consumerGroup = "${rocketmq.consumer.group}", topic = "id")
@Slf4j
public class IdListener implements RocketMQListener<Order1> {
    @Resource
    private WebSocketServer webSocketServer;

    @SneakyThrows
    @Override
    public void onMessage(Order1 order) {
        StoreOrderDto storeOrderDto = BeanUtil.copyProperties(order, StoreOrderDto.class);
        webSocketServer.sendInfo(storeOrderDto,order.getBusinessmanId()+"");
    }
}
